#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include "berdecoder.h"

typedef void (*ber_handler)();

struct ber_handler_tree
{
  ber_handler *leaves;
  struct ber_handler_tree *children;
};

void
leaf(const BerHead *h, BYTE *buf)
{
  int i;
  printf("head: %d, %d -- ", h->tag, h->length);
  for (i=0; i<h->length; i++)
    printf("%x  ", *(buf+i));
  printf("\n");
}

void
enter(const BerHead *h, BYTE *buf)
{
  printf("enter tag: %d {\n", h->tag);
}

void
out()
{
  printf("}");
}

int
main(int argc, char *argv[])
{
  char file_name[256];
  if (argc!=2) {
    printf("Usage: %s data_file", argv[0]);
    exit(1);
  }
  
  strcpy(file_name, argv[1]);

  FILE *fp;
  if ((fp=fopen(file_name, "rb"))==NULL) {
    printf("cannot open file!\n");
    exit(1);
  }

  ber_set_callback(enter, out, leaf);
  return 0;
}
